#include "mover.h"
#include "GraphicsArea/drawingarea.h"

//************************************************************* Constructor

Mover::Mover(DrawingArea* drawingAreaUse,QDockWidget* dockInfoToolP) : ToolEffect(drawingAreaUse){
    dockInfoTool = dockInfoToolP;
    drawingAreaUse->XBeginSelection = 0;
    drawingAreaUse->XEndSelection = 0;
    drawingAreaUse->YBeginSelection = 0;
    drawingAreaUse->YEndSelection=0;
}

//************************************************************* Affichage of Dock Tool Info

void Mover::createAffichage(){
    QWidget* widgetInfoToolUp = new QWidget();
    QWidget* widgetInfoTool = new QWidget(widgetInfoToolUp);
    QGridLayout* layoutInfoTool = new QGridLayout();

    QLabel *labelInfoGenTool = new QLabel();


    labelInfoGenTool->setText(QString::fromUtf8("Déplacement du calque : cliquez sur l'image et déplacez-la"));


    layoutInfoTool->addWidget(labelInfoGenTool, 0, 0, Qt::AlignVCenter);

    widgetInfoTool->setLayout(layoutInfoTool);
    dockInfoTool->setWidget(widgetInfoToolUp);
}

//************************************************************* Mover movement

void Mover::initMove(int x, int y){
    layerToMove = drawingArea->getCurrentLayer();
    differenceXToLayer = x - (int) layerToMove->x();
    differenceYToLayer = y - (int) layerToMove->y();
}

void Mover::moving(int x, int y){
    layerToMove->setPos(x - differenceXToLayer, y - differenceYToLayer);
}
